from trinity.sceneRenderJobBase import SceneRenderJobBase
import trinity
import blue

def CreateSceneRenderJobCharacters(name = None):
    newRJ = SceneRenderJobCharacters()
    if (name is not None):
        newRJ.ManualInit(name)
    else:
        newRJ.ManualInit()
    return newRJ



class SceneRenderJobCharacters(SceneRenderJobBase):
    renderStepOrder = ['UPDATE_SCENE',
     'UPDATE_UI',
     'UPDATE_BACKDROP',
     'CLEAR',
     'SET_PROJECTION',
     'SET_VIEW',
     'RENDER_BACKDROP',
     'RENDER_SCENE',
     'RENDER_SCULPTING',
     'RENDER_TOOLS',
     'RENDER_UI']

    def _ManualInit(self, name = 'SceneRenderJobCharacters'):
        self.ui = None



    def _SetScene(self, scene):
        self.SetStepAttr('UPDATE_SCENE', 'object', scene)
        self.SetStepAttr('RENDER_SCENE', 'scene', scene)



    def _CreateBasicRenderSteps(self):
        self.AddStep('UPDATE_SCENE', trinity.TriStepUpdate(self.GetScene()))
        self.AddStep('CLEAR', trinity.TriStepClear((0.0, 0.0, 0.0, 0.0), 1.0))
        self.AddStep('RENDER_SCENE', trinity.TriStepRenderScene(self.GetScene()))



    def DoReleaseResources(self, level):
        return 



    def DoPrepareResources(self):
        return 



    def SetUI(self, ui):
        if (ui is None):
            self.RemoveStep('UPDATE_UI')
            self.RemoveStep('RENDER_UI')
        else:
            self.AddStep('UPDATE_UI', trinity.TriStepUpdate(ui))
            self.AddStep('RENDER_UI', trinity.TriStepRenderUI(ui))



    def SetBackdrop(self, backdrop):
        if (backdrop is None):
            self.RemoveStep('UPDATE_BACKDROP')
            self.RemoveStep('RENDER_BACKDROP')
        else:
            self.AddStep('UPDATE_BACKDROP', trinity.TriStepUpdate(backdrop))
            self.AddStep('RENDER_BACKDROP', trinity.TriStepRender(backdrop))



    def SetSculpting(self, sculpting):
        if (sculpting is None):
            self.AddStep('RENDER_SCULPTING', trinity.TriStepRunJob(sculpting))
        else:
            self.RemoveStep('RENDER_SCULPTING')



    def SetActiveCamera(self, camera):
        if (camera is None):
            self.RemoveStep('SET_VIEW')
            self.RemoveStep('SET_PROJECTION')
        else:
            self.AddStep('SET_VIEW', trinity.TriStepSetView(camera.viewMatrix))
            self.AddStep('SET_PROJECTION', trinity.TriStepSetProjection(camera.projectionMatrix))



    def EnableSceneUpdate(self, isEnabled):
        if isEnabled:
            self.AddStep('UPDATE_SCENE', trinity.TriStepUpdate(self.GetScene()))
        else:
            self.RemoveStep('UPDATE_SCENE')



    def EnableBackBufferClears(self, isEnabled):
        if isEnabled:
            self.AddStep('CLEAR', trinity.TriStepClear((0.0, 0.0, 0.0, 0.0), 1.0))
        else:
            self.RemoveStep('CLEAR')




